public class Test {
    public static int find(int[] arr, int key){
        int left = 0;
        int right = arr.length-1;
        int mid = 0;
        while(left<=right){
            mid = (left+right)/2;
            if(arr[mid] == key){
                return mid;
            }else if(arr[left]<key){
                left = mid+1;
            }else {
                right = mid-1;
            }
        }
        return -1;
    }
    public static void main(String[] args) {
        int[] arr = new int[]{1,2,3,4};
        System.out.println(find(arr, 99));
        System.out.println(find(arr, 9));
        System.out.println(find(arr, 1));
        System.out.println(find(arr, 4));
    }
}
